using System;
using System.Collections.Generic;

namespace LannyPractiseCode.Shu
{
    //创建结点类
    //为了让HuffmanCodeNode对象持续排序Collections集合排序
    //让Node实现IComparable接口
    public class HuffmanCodeNode : IComparable<HuffmanCodeNode>
    {
        //存放数据（字符）本身，比如 'a'=>97  
        public Byte data { set; get; }
        //权值，表示字符出现的次数
        public int Weight { set; get; }
        public HuffmanCodeNode Left;
        public HuffmanCodeNode Right;
        public HuffmanCodeNode(Byte data, int weight)
        {
            this.data = data;
            this.Weight = weight;
        }
        public override string ToString()
        {
            return "Node [data=" + data + ",weight=" + this.Weight + "]";
        }
        public int CompareTo(HuffmanCodeNode obj)
        {
            return this.Weight - obj.Weight;
        }
        //前序遍历
        public void PreOrder()
        {
            System.Console.WriteLine(this+" ");
            if (this.Left != null)
                this.Left.PreOrder();
            if (this.Right != null)
                this.Right.PreOrder();
        }
    }
}